package com.paper.tiger.easy.rpc.center.handler;

import com.paper.tiger.easy.rpc.core.RegisterData;
import com.paper.tiger.easy.rpc.core.ServerType;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.util.ReferenceCountUtil;

/**
 *  心跳 handler 维持心跳,客户端发送心跳包过来,响应心跳包
 */
public class HeartBeatHanler extends ChannelInboundHandlerAdapter {

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {

        RegisterData data = (RegisterData) msg;
        // 接收客户端心跳信息
        if (data.getType().equals(ServerType.HEART_BEAT_REQ.getCode())){
            ReferenceCountUtil.release(msg);
        }else {
            // 如果不是心跳包,向下个handler 传递
            ctx.fireChannelRead(msg);
        }

    }


}
